package org.codeart.apipassenger.controller;

import org.codeart.apipassenger.service.UserService;
import org.codeart.common.dto.PassengerUser;
import org.codeart.common.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class UserController {
    
    @Autowired
    private UserService userService;
    
    @GetMapping("/users")
    public R<PassengerUser> users(HttpServletRequest request) {
        // 从请求头中获取accessToken
        String token = request.getHeader("Authorization");
        // 根据accessToken查询
        PassengerUser user = userService.getUserByAccessToken(token);
        return R.ok(user);
    }

}
